<extend name="Layout:layout"/>

<block name="css">
    <link rel="stylesheet" href="">
    <!-- Metis Theme stylesheet -->
    <link rel="stylesheet" href="__PUBLIC__/metis/assets/lib/datatables/3/dataTables.bootstrap.css">

    <style type="text/css"></style>
</block>

<block name="srcjs">
    <script type="text/javascript" src=""></script>
</block>

<block name="content">

    <div class="row ui-sortable">
        <div class="col-lg-12">
            <!--Begin Datatables-->
            <div class="row">
                <div class="col-lg-12">
                    <div class="box">
                        <header>
                            <div class="icons"> <i class="fa fa-table"></i>
                            </div>
                            <h5>文档列表</h5>
                        </header>
                        <div class="body">
                            <table id="dataTable" class="table table-bordered table-condensed table-hover table-striped text-center">
                                <thead>
                                    <tr>
                                        <th class="text-center">序号</th>
                                        <th class="text-center">编号</th>
                                        <th class="text-center">名称</th>
                                        <th class="text-center">描述</th>
                                        <th class="text-center">类型</th>
                                        <th class="text-center">图片数量</th>
                                        <th class="text-center">最后操作者</th>
                                        <th class="text-center">更新时间</th>
                                        <th class="text-center">操作</th>

                                    </tr>
                                </thead>
                                <tbody>

                                <volist name="picDocTableData" id="item" key="k">
                                    <tr>
                                        <td>{$k}</td>
                                        <td>{$item.pdoc_sn}</td>
                                        <td>{$item.pdoc_name}</td>
                                        <td>{$item.pdoc_describe}</td>
                                        <td>{$item.pdoc_catagory}</td>
                                        <td>{$item.pdoc_pic_number}</td>
                                        <td>{$item.pdoc_create_person}</td>
                                        <td>{$item.pdoc_createtime}</td>
                                        <td>
                                            <if condition=" $_SESSION['current_user']['group_id'] == 1 ">
                                                <button 
                                                    class="btn btn-xs btn-danger" 
                                                    data-pdoc-id="{$item.pdoc_id}" 
                                                    data-pdoc-sn="{$item.pdoc_sn}" 
                                                    data-name="btnDel" 
                                                    style="color: #888">
                                                    删除
                                                </button>
                                                <button 
                                                    class="btn btn-xs btn-info" 
                                                    data-name="btnEdit" 
                                                    data-pdoc-id="{$item.pdoc_id}"
                                                    data-pdoc-name="{$item.pdoc_name}"
                                                    data-pdoc-describe="{$item.pdoc_describe}"
                                                    data-toggle="modal" 
                                                    data-target="#updatePicDocModal">
                                                    修改
                                                </button>
                                            </if>
                                    
                                            <a href="{:U('updatePage')}?pdoc_id={$item.pdoc_id}" class="btn btn-xs btn-default">更新</a>
                                            <a href="{:U('preViewPage')}?pdoc_id={$item.pdoc_id}" class="btn btn-xs btn-default">预览</a>
                                    
                                        </td>

                                    </tr>
                                </volist>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.row -->
        </div>
    </div>


    <!-- Modal -->
    <div class="modal fade" id="updatePicDocModal" tabindex="-1" role="dialog" aria-labelledby="updatePicDocModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="updatePicDocModalLabel">更新学习文档</h4>
                </div>
                <div class="modal-body">

                    <form class="form-horizontal" role="form">

                        <div class="form-group">
                            <label for="pdoc_old_name" class="col-sm-2 control-label">原名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-read" id="pdoc_old_name" readonly="true"></div>
                        </div>

                        <div class="form-group">
                            <label for="pdoc_name" class="col-sm-2 control-label">新名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="pdoc_name" ></div>
                        </div>

                        <div class="form-group">
                            <label for="pdoc_describe" class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="pdoc_describe" ></div>
                        </div>

                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" id="btnSubmitUpdatePicDoc" class="btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="customjs">

    <script src="__PUBLIC__/metis/assets/lib/datatables/jquery.dataTables.js"></script>
    <script src="__PUBLIC__/metis/assets/lib/datatables/3/dataTables.bootstrap.js"></script>

    <script>
        $(function () {

            $('#dataTable').dataTable({
                "scrollX": true,
                "language": dtChinese
            });

            $("#dataTable").delegate("[data-name='btnDel']", "click", function () {
                if (confirm("确认要删除吗？")) {

                    var sendData = {
                        "pdoc_id": $(this).attr("data-pdoc-id"),
                        "pdoc_sn": $(this).attr("data-pdoc-sn")
                    };

                    $.post("{:U('delPicDoc')}", sendData).done(function (responseData) {
                        //console.log(responseData);
                        if (responseData.status == 1) {
                            alert(responseData.info);
                            location.href = responseData.jumpUrl;
                        } else {
                            alert(responseData.info);
                        }
                    });

                }
            });

            var pdoc_id = -1;

            $("#dataTable").delegate("[data-name='btnEdit']", "click", function () {

                $("#pdoc_old_name").val($(this).attr("data-pdoc-name"));
                $("#pdoc_describe").val($(this).attr("data-pdoc-describe"));
                pdoc_id = $(this).attr("data-pdoc-id");

            });

            $("#btnSubmitUpdatePicDoc").click(function () {

                var pdoc_name = $.trim($("#pdoc_name").val());
                if (pdoc_name == "") {
                    alert("请先输入文档名称");
                    $("#pdoc_name").focus();
                    return;
                }

                var sendData = {
                    "pdoc_id": pdoc_id,
                    "pdoc_name": pdoc_name,
                    "pdoc_describe": $.trim($("#pdoc_describe").val())
                };
                //console.log(sendData);
                $.post("{:U('modifyPicDoc')}", sendData).done(function (responseData) {
                    if (responseData.status === 1) {
                        alert(responseData.info);
                        location.href = responseData.jumpUrl;
                    } else {
                        alert(responseData.info);
                    }
                });

            });

        });
    </script>
    <include file="index.js" />

</block>